<template>
    <div class="citylist" ref="wrapper">
      <div>
        <div class="title">当前城市</div>
        <div class="box">
          <div class="cityitem">{{this.$store.state.city}}</div>
        </div>
        <div class="title">热门城市</div>
        <div class="box">
            <div class="cityitem"  v-for="item in hot" :key="item.id" @click="handlechangecity(item.name)">
              {{item.name}}
            </div>
        </div>
        <div v-for="(item,key) in citylist" :key="key" :ref="key">
          <div class="title tit3" >{{key}}</div>
          <div class="box-column">
            <div class="cityitem-all"
                 v-for="inneritem in item"
                 :key="inneritem.id"
                 @click="handlechangecity(inneritem.name)"
            >
              {{inneritem.name}}
            </div>
          </div>
        </div>
      </div>
    </div>
</template>

<script>
import Bscroll from 'better-scroll'
export default {
  name: 'citylist',
  props: {
    citylist: Object,
    hot: Array,
    apl: String
  },
  methods: {
    handlechangecity (city) {
      this.$store.commit('changecity', city)
      this.$router.push('/')
    }
  },
  mounted () {
    const options = {
      click: true,
      tap: true
    }
    this.scroll = new Bscroll(this.$refs.wrapper, options)
  },
  watch: {
    apl (e) {
      if (this.apl) {
        const el = this.$refs[this.apl][0]
        this.scroll.scrollToElement(el)
      }
    }
  }
}
</script>

<style scoped>
  .citylist{
    position: absolute;
    max-width: 768px;
    margin: 0 auto;
    top: 95px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
  }
  .title{
    background: #eaeaea;
    padding: 5px 0 5px 10px;
    color: #8d8d8d;
    margin-bottom: 10px;
  }
  .tit3{
    margin-bottom: 3px;
  }
  .box{
    padding: 2px;
  }
  .box-column{

  }
  .cityitem{
    display: inline-block;
    width: 30%;
    padding: 4px 0;
    margin: 8px 4px;
    margin-top: 0;
    border: 1px solid #ccc;
    border-radius: 5px;
    text-align: center;
    font-size: 0.95rem;
  }
  .cityitem-all{
    line-height: 35px;
    padding-left: 12px;
    border-bottom: 1px solid #f2f2f2;
  }
</style>
